<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MQ</title>
    <script type='module' src="../src/js/mq.js"></script>
</head>

<body>
    <div><input><button>发送</button></div>
</body>

<script defer="true" type="text/javascript">
    import("../src/js/mq.js").then(({ default: JscMQ }) => {
        let mq = new JscMQ();

        mq.register('hi', '1', function (msg) {
            let div = document.createElement('div');
            div.append(msg.msg.data);
            document.querySelector('body').appendChild(div);
        });
        document.querySelector('button').addEventListener('click', function (e) {
            let input = document.querySelector('input');
            mq.postMsg('hi', { sender: 'button', data: input.value });
            input.value = '';
        });
    });
</script>

</html>